package game;

import java.awt.event.FocusEvent;
import java.util.*;

public class Doudizhu {
    private ArrayList<Card> list = new ArrayList();
    private String[] str = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};

    // 初始化54张扑克牌
    public void init() {
        for (int i = 0; i < str.length; i++) {
            list.add(new Card(str[i], "♠"));
            list.add(new Card(str[i], "♥"));
            list.add(new Card(str[i], "♣"));
            list.add(new Card(str[i], "♦"));
        }

        list.add(new Card("小王", "Joker"));
        list.add(new Card("大王", "Joker"));
        System.out.println(list);
    }

    // 洗牌
    public void xipai() {
        Collections.shuffle(list);
        System.out.println(list);
    }

    // 发牌
    public void fapai() {

        System.out.println(paixu(list.subList(0, 17)));

        System.out.println(paixu(list.subList(17, 34)));

        System.out.println(paixu(list.subList(34, 51)));
        System.out.println(list.subList(51, 54));


    }
//扑克牌排序
    public List paixu(List sulist) {
        sulist.sort(new Comparator<Card>() {
            @Override
            public int compare(Card c1, Card c2) {
                int index1 = -1;
                int index2 = -1;
                if (c1.getPoint().equals("大王")) {
                    index1 = 14;

                } else if (c1.getPoint().equals("小王")) {
                    index1 = 13;
                }
                if (c2.getPoint().equals("大王")) {
                    index2 = 14;

                } else if (c2.getPoint().equals("小王")) {
                    index2 = 13;
                }
                for (int i = 0; i < str.length; i++) {
                    if (c1.getPoint().equals(str[i])) {
                        index1 = i;
                    }
                    if (c2.getPoint().equals(str[i])) {
                        index2 = i;
                    }
                }
                return index1 - index2;
            }
        });
        return sulist;
    }

    public static void main(String[] args) {
        Doudizhu doudizhu = new Doudizhu();
        doudizhu.init();
        doudizhu.xipai();
        doudizhu.fapai();
    }
}
